home *** CD-ROM | disk | FTP | other *** search
- #include <Folders.h>
- #include "FinderToFSSpec.h"
-
- void FindName(FinderHandle fh, StringPtr name)
- {
- int i;
- Boolean gotName = FALSE;
-
- // (* find where the name starts by looking for “$0BEA” in the Finder™’s object handle *)
-
- for (i=0; i<=GetHandleSize((Handle)fh)-2; i++) {
- if (!gotName) {
- gotName = (((*(unsigned char **)fh)[i] == 0x0B) && ((*(unsigned char **)fh)[i+1] == 0xEA));
- if (gotName)
- break;
- }
- }
-
- if (gotName)
- BlockMove((((Ptr)(*fh))+i+4), name, 32);
- else
- name[0] = 0;
- }
-
- void FinderHandleToFSSpec(FinderHandle fh, FSSpecPtr f)
- {
- short i, tvrefnum, dvrefnum;
- Boolean b;
- long tdirid, ddirid;
- CInfoPBRec cipb;
-
- i = FindFolder(kOnSystemDisk, kTrashFolderType, kDontCreateFolder, &tvrefnum, &tdirid);
- i = FindFolder(kOnSystemDisk, kDesktopFolderType, kDontCreateFolder, &dvrefnum, &ddirid);
-
- f->vRefNum = (*fh)->fvRefNum;
- /*
- (* the Finder™ normally stores the parent directory in the “fparenth” field of the FinderHandle. But if the file/folder is in the *)
- (* “Desktop Folder” then the “fdirID” may not be valid for the given “fvRefNum”. We check if “fvRefNum” matches and if not *)
- (* then we use the alternative method - actually what the Finder™ also uses! *)
- */
- if ((*fh)->fDirID == 2)
- f->parID = 1;
- else if (((*fh)->fvRefNum == tvrefnum) && ((*fh)->fDirID == tdirid)) {
- /*
- (* special case for the Trash. This icon sits on the Finder™ desktop and has to be taken into account. We check for the same *)
- (* “fvRefNum” and “fDirID”. If these match then get the name for the folder from a _GetCatInfo and Exit(FinderHandleToFSSpec *)
- */
-
- cipb.hFileInfo.ioCompletion = 0L;
- cipb.hFileInfo.ioNamePtr = (StringPtr)f->name;
- cipb.hFileInfo.ioVRefNum = f->vRefNum;
- cipb.hFileInfo.ioDirID = tdirid;
- cipb.hFileInfo.ioFDirIndex = -1;
- i = PBGetCatInfoSync(&cipb);
- f->parID = cipb.dirInfo.ioDrParID;
- return;
- }
- else if (((*fh)->fvRefNum == dvrefnum) && ((*fh)->fDirID == ddirid)) {
- cipb.hFileInfo.ioCompletion = 0L;
- cipb.hFileInfo.ioNamePtr = (StringPtr)f->name;
- cipb.hFileInfo.ioVRefNum = f->vRefNum;
- cipb.hFileInfo.ioDirID = ddirid;
- cipb.hFileInfo.ioFDirIndex = -1;
- i = PBGetCatInfoSync(&cipb);
- f->parID = cipb.dirInfo.ioDrParID;
- return;
- }
- else {
- if ((*(**fh).fParentH)->fvRefNum != f->vRefNum) {
- if (((*fh)->fvRefNum == tvrefnum) && ((*fh)->fDirID = tdirid))
- i = FindFolder(f->vRefNum, kTrashFolderType, kDontCreateFolder, &tvrefnum, &f->parID);
- else if (((*fh)->fvRefNum == dvrefnum) && ((*fh)->fDirID == ddirid))
- i = FindFolder(f->vRefNum, kDesktopFolderType, kDontCreateFolder, &dvrefnum, &f->parID);
- else if ((*(*fh)->fMainDirH)->fDesktopH != 0L)
- f->parID = (*(*(*fh)->fMainDirH)->fDesktopH)->fDirID;
- else
- f->parID = -1;
- }
- else {
- f->parID = (*(*fh)->fParentH)->fDirID;
- }
- }
-
- FindName(fh, f->name);
- }
-